<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="js/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="layui/layui.js" ></script>
		<script type="text/javascript" src="js/publicurl.js" ></script>
		<style>
			.recall{
				float: right;
				margin-right: 15px;
				color: red;
				font-size: 16px;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav top-header" style="line-height: 35px;">
			
		    <a id="myapply" href="javascript:;" style="position: absolute;" class="mui-action-back">
		    	<span class="mui-icon mui-icon-arrowleft"></span>
		    	返回
		    </a>
		    <h1 class="mui-title" id="applytitle"></h1>
		</header>
		<div class="mui-content">
		    <!--报修申请-->
		    <div id="applycontent" style="display: none;">
			    <!--<div class="mui-card">
					<div class="mui-card-header">页眉</div>
					<div class="mui-card-content">
						<div class="mui-card-content-inner">
							123
						</div>
					</div>
					<div class="mui-card-footer">页脚</div>
				</div>-->
		    </div>
		    <!--入住申请-->
		    <div id="stayApply" style="display: none;">
		    </div>
		    <!--退宿申请-->
		    <div id="retireApply" style="display: none;">
		    	<!--<div class="mui-card">
					<div class="mui-card-header">申请记录</div>
					<div class="mui-card-content">
						<div class="mui-card-content-inner">
							123
						</div>
					</div>
					<div class="mui-card-footer">页脚</div>
				</div>-->
		    </div>
		    <!--押金申请-->
		    <div id="depositApply" style="display: none;">
		    	
		    </div>
		    <!--交租申请-->
		    <div id="rentApply" style="display: none;">
		    	
		    </div>
		</div>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript">
			var userInfo = JSON.parse(localStorage.getItem("userInfo"));
			var userId = userInfo;
			mui.init({
				swipeBack:true,//启用右滑关闭功能
				
			});
			var url=window.location.href;
			var id=url.split("?")[1].split("=")[1];
			layui.use(['layer','form'],function() {
				var layer = layui.layer;
				var form = layui.form;
				/*报修申请*/
				if(id==1) {

					
					$("#applycontent").show();
					$("#applytitle").html("报修申请记录");
					mui.ajax(puburl.url+"/dangxia/user/getRepairApplyByUserId", {
						data: {
							"userId":userId
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 5000, //超时时间设置为10秒；
						success: function(data1) {
							if(data1.code==0) {
								$("#applycontent").empty();
								layer.msg(data1.msg);
								
								$.each(data1.data, function(index,d) {
									addElement("applycontent",d);
									
								});
								
								
							} else {
								layer.msg(data1.msg);
							}
						},
						error: function(xhr, type, errorThrown) { //异常处理；
							layer.msg("连接异常");
						}
					});
					$("#applycontent").on('click','.recall',function() {
						var idval = $(this).attr("id");
						recallOper(puburl.url+"/dangxia/user/updateStatusById",idval,1);
					});
				}
				/*入住申请*/
				if(id==2) {
					$("#applytitle").html("入住申请记录");
					$("#stayApply").show();
					mui.ajax(puburl.url+"/dangxia/user/getStayApplyByUserId", {
						data: {
							"userId":userId
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 5000, //超时时间设置为10秒；
						success: function(data1) {
							if(data1.code==0) {
								$("#stayApply").empty();
								layer.msg(data1.msg);
								
								$.each(data1.data, function(index,d) {
									var stat = "";
									var recall = "";
									var reason="";
									if(d.status==0) {
										stat = "待审核";
										recall = "撤回";
									} else if(d.status==1) {
										stat = "已通过";
									}else if(d.status==2) {
										stat = "已驳回";
										reason="<p>驳回理由:"+d.remarks+"</p>";
									} else if(d.status==3) {
										stat = "已撤回";
										
									}
									$("#stayApply").append(
										"<div class='mui-card'>"
											+"<div class='mui-card-header'>申请时间"+d.apply_time+"</div>"
											+"<div class='mui-card-content'>"
												+"<div class='mui-card-content-inner'>"
													+"申请详情<br/>"
													+"小区:"+d.area_name
													+"&nbsp;&nbsp;楼栋:"+d.building_name
													+"&nbsp;&nbsp;房间号:"+d.room_no
													+"&nbsp;&nbsp;床位:"+d.bed_num+"号<br/>"
													+"申请状态:"+stat
													+reason
												+"</div>"
											+"</div>"
											+"<div class=mui-card-footer>"
											+"<a href='javascript:;' class='stayrecall' id='"+d.id+"'>"+recall+"</a>"
											+"</div>"
										+"</div>"
									);
									
								});
								
								
							} else {
								layer.msg(data1.msg);
							}
						},
						error: function(xhr, type, errorThrown) { //异常处理；
							layer.msg("连接异常");
						}
					});
					$("#stayApply").on('click','.stayrecall',function() {
						var idval = $(this).attr("id");
						recallOper(puburl.url+"/dangxia/user/updateStayApplyStatus",idval,3);
					});
				}
				
				/*退宿申请*/
				if(id==3) {
					$("#applytitle").html("退宿申请");
					$("#retireApply").show();
					mui.ajax(puburl.url+"/dangxia/user/getRetireApply", {
						data: {
							"userId":userId
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 5000, //超时时间设置为10秒；
						success: function(data1) {
							if(data1.code==0) {
								$("#retireApply").empty();
								layer.msg(data1.msg);
								
								$.each(data1.data, function(index,d) {
									var stat = "";
									var recall = "";
									var reason="";
									if(d.status==0) {
										stat = "待审核";
										recall = "撤回";
									} else if(d.status==1) {
										stat = "已通过";
									}else if(d.status==2) {
										stat = "已驳回";
										reason="<p>驳回理由:"+d.remarks+"</p>";
									} else if(d.status==3) {
										stat = "已撤回";
										
									}
									$("#retireApply").append(
										"<div class='mui-card'>"
											+"<div class='mui-card-header'>申请时间"+d.apply_time+"</div>"
											+"<div class='mui-card-content'>"
												+"<div class='mui-card-content-inner'>"
													+"退宿详情<br/>"
													+"小区:"+d.area_name
													+"&nbsp;&nbsp;楼栋:"+d.building_name
													+"&nbsp;&nbsp;房间号:"+d.room_no
													+"&nbsp;&nbsp;床位:"+d.bed_num+"号<br/>"
													+"申请状态:"+stat
													+reason
												+"</div>"
											+"</div>"
											+"<div class=mui-card-footer>"
											+"<a href='javascript:;' class='retireclass' id='"+d.id+"'>"+recall+"</a>"
											+"</div>"
										+"</div>"
									);
									
								});
								
								
							} else {
								layer.msg(data1.msg);
							}
						},
						error: function(xhr, type, errorThrown) { //异常处理；
							layer.msg("连接异常");
						}
					});
					$("#retireApply").on('click','.retireclass',function() {
						var idval = $(this).attr("id");

						recallOper(puburl.url+"/dangxia/user/updateRetireApplyStatus",idval,3);
					});
				}
				/*缴纳押金申请*/
				if(id==4) {
					$("#applytitle").html("押金申请记录");
					$("#depositApply").show();
					mui.ajax(puburl.url+"/dangxia/user/getDepositApply", {
						data: {
							"userId":userId
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 5000, //超时时间设置为10秒；
						success: function(data1) {
							if(data1.code==0) {
								$("#depositApply").empty();
								layer.msg(data1.msg);
								
								$.each(data1.data, function(index,d) {
									var stat = "";
									var recall = "";
									var reason="";
									if(d.status==0) {
										stat = "待审核";
										recall = "撤回";
									} else if(d.status==1) {
										stat = "已通过";
									}else if(d.status==2) {
										stat = "已驳回";
										reason="<p>驳回理由:"+d.remarks+"</p>";
									} else if(d.status==3) {
										stat = "已撤回";
										
									}
									$("#depositApply").append(
										"<div class='mui-card'>"
											+"<div class='mui-card-header'>申请时间"+d.apply_time+"</div>"
											+"<div class='mui-card-content'>"
												+"<div class='mui-card-content-inner'>"
													+"押金详情<br/>"
													+"金额:"+d.money+"元<br/>"
													+"申请状态:"+stat
													+reason
												+"</div>"
											+"</div>"
											+"<div class=mui-card-footer>"
											+"<a href='javascript:;' class='depositclass' id='"+d.id+"'>"+recall+"</a>"
											+"</div>"
										+"</div>"
									);
									
								});
								
								
							} else {
								layer.msg(data1.msg);
							}
						},
						error: function(xhr, type, errorThrown) { //异常处理；
							layer.msg("连接异常");
						}
					});
					$("#depositApply").on('click','.depositclass',function() {
						var idval = $(this).attr("id");

						recallOper(puburl.url+"/dangxia/user/updateDepositApplyStatus",idval,3);
					});
				}
				if(id==5) {
					$("#applytitle").html("交租申请记录");
					$("#rentApply").show();
					mui.ajax(puburl.url+"/dangxia/user/getPayRentApply", {
						data: {
							"userId":userId
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 5000, //超时时间设置为10秒；
						success: function(data1) {
							if(data1.code==0) {
								$("#rentApply").empty();
								layer.msg(data1.msg);
								
								$.each(data1.data, function(index,d) {
									var stat = "";
									var recall = "";
									var reason="";
									if(d.status==0) {
										stat = "待审核";
										recall = "撤回";
									} else if(d.status==1) {
										stat = "已通过";
									}else if(d.status==2) {
										stat = "已驳回";
										reason="<p>驳回理由:"+d.remarks+"</p>";
									} else if(d.status==3) {
										stat = "已撤回";
										
									}
									$("#rentApply").append(
										"<div class='mui-card'>"
											+"<div class='mui-card-header'>申请时间"+d.apply_time+"</div>"
											+"<div class='mui-card-content'>"
												+"<div class='mui-card-content-inner'>"
													+"租金详情<br/>"
													+"金额:"+d.pay_amount+"元<br/>"
													+"申请住宿时长"+d.month_num+"天<br/>"
													+"申请状态:"+stat
													+reason
												+"</div>"
											+"</div>"
											+"<div class=mui-card-footer>"
											+"<a href='javascript:;' class='rentclass' id='"+d.id+"'>"+recall+"</a>"
											+"</div>"
										+"</div>"
									);
									
								});
								
								
							} else {
								layer.msg(data1.msg);
							}
						},
						error: function(xhr, type, errorThrown) { //异常处理；
							layer.msg("连接异常");
						}
					});
					$("#rentApply").on('click','.rentclass',function() {
						var idval = $(this).attr("id");
						layer.msg(idval);
						recallOper(puburl.url+"/dangxia/user/updatePayRentApplyStatus",idval,3);
					});
				}
			});
			/*报修申请拼接*/
			function addElement(idname,d) {
				var btn = "";
				
				var sta = "";
				var ctime;
				if(d.complete_time!=null) {
					ctime=d.complete_time;
				} else {
					ctime="";
				}
				if(d.status==0) {
					sta = "待审核";
					btn = "撤回";
				} else if(d.status==1) {
					sta = "处理中";
				} else if(d.status==2){
					sta = "已处理";
				} else if(d.status==3) {
					sta = "已撤回";
				}
				$("#"+idname).append(
					"<div class='mui-card'>"										
						+"<div class='mui-card-header'>"+d.repair_title+"</div>"
						+"<div class='mui-card-content'>"
							+"<div class='mui-card-content-inner'>"
								+d.repair_desc
							+"</div>"
						+"</div>"
						+"<div class='mui-card-footer'>"
						+"报修日期:"+d.repair_time+"<br/>"
						+"状态:"+sta+"<br/>"
						+"处理时间"+ctime
						+"</div>"
						+"<div>"
						+"<a href='javascript:;' class='recall' id='"+d.id+"'>"+btn+"</a>"
						+"</div>"
					+"</div>" 
				);
			}
			/*撤回操作封装*/
			/*puburl.url+"/dangxia/user/updateStatusById"*/
			function recallOper(url,idname,status){
				if(confirm("确定要撤回么？")) {
					$.post(url,
						{
							"id":idname,
							"status":status
						},
						function(data1) {
							if(data1.code==0) {
								layer.msg("<span style='color:green'>"+data1.msg+"</span>",{
									icon:1,
									time:800,
									end:function() {
										window.location.reload();
									}
								});
							} else {
								layer.msg("<span style='color:green'>"+data1.msg+"</span>",{
									icon:1,
									time:800
								});
							}
						}
					);
				}
			}
		</script>
	</body>

</html>